import { getPie3D } from "@renderer/utils/handleSurface";
export const handelResponseData = (data: any, layoutItem: any) => {
  let obj = JSON.parse(JSON.stringify(layoutItem.props));
  if (!layoutItem.props.series || layoutItem.props.series.length <= 0) {
    console.log("obj", obj);
    return obj;
  }
  let seriesItem = JSON.parse(JSON.stringify(layoutItem.props.series));
  let seriesArr = [];
  console.log("data", data);
  if (
    data &&
    seriesItem[0].type != "pie" &&
    seriesItem[0].type != "gauge" &&
    seriesItem[0].type != "radar" &&
    seriesItem[0].type != "surface" &&
    data.data &&
    data.data.length > 0
  ) {
    if (obj.xAxis) {
      obj.xAxis.data = data.xAxis || [];
    }

    data.data.forEach((ele, index) => {
      let it = seriesItem[index] || seriesItem[0];
      seriesArr.push({
        ...it,
        name: ele.name,
        data: ele.value,
      });
    });
    obj.series = seriesArr;
  } else if (
    seriesItem[0].type == "pie" ||
    seriesItem[0].type == "gauge" ||
    seriesItem[0].type == "radar" ||
    seriesItem[0].type == "surface"
  ) {
    if (seriesItem[0].type == "surface") {
      obj.series = getPie3D(data, 0);
    } else {
      obj.series = [
        {
          ...seriesItem[0],
          data: data,
        },
      ];
    }
  }
  console.log("obj", obj);
  return obj;
};
